﻿using System;

namespace Demo4.Anonymous
{
    public class Main
    {
        /// <summary>
        /// 匿名类型
        /// </summary>
        private Main()
        {
            //匿名类
            var dude = new {Name = "Bob", Age = 23};
            Console.WriteLine(dude.Name);

            //特殊绑定
            int Age = 23;
            var dude2 = new {Name = "Bob", Age, Age.ToString().Length};
            Console.WriteLine($"Name:{dude2.Name},Age: {dude2.Age}, Length: {dude2.Length}");
            
            //无法有效获得类型时
            dynamic dudes = new[]
            {
                new {Name = "Bob", Age = 30},
                new {Name = "Bob", Age = 30}
            };
            
        }

        public static Main NewInstance()
        {
            return new Main();
        }
    }
}